﻿@model ConferenceMailServerModel
@{
	ViewBag.Title = Resources.ConferenceMailServer + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.Mail：<input id="selMail" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMailServer, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceMailServer" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtConferenceName" disabled class="easyui-textbox" style="height:27px; width:300px;" value="@ViewBag.ConferenceName">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Mail：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtMail" name="mail" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['email','length[1,100]']">
							<input type="hidden" id="hidId" name="id" />
							<input type="hidden" id="hidConferenceId" name="ConferenceId" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.MailServer：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtMailServer" name="MailServer" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.MailPassword：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtMailPassword" name="MailPassword" type="password" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.MailType：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlMailType" name="MailType" class="easyui-combobox" style="height:27px; width:300px;" data-options="required:true,editable:false, panelHeight:'auto'">
								<option value="@ConstValues.MailType.会议邮箱">@Resources.MailConference</option>
								<option value="@ConstValues.MailType.注册服务邮箱">@Resources.MailAttendence</option>
								<option value="@ConstValues.MailType.投稿服务邮箱">@Resources.MailContribute</option>
								<option value="@ConstValues.MailType.酒店交通服务邮箱">@Resources.MailHotelTraffic</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.CcMail：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtCcMail" name="CcMail" class="easyui-textbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtRemark" name="remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceMailServer");
	common.setCurrentParentMenu("#menu_a6");

	$(function () {
		$("#selMail").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceMailServerController.GetData),nameof(ConferenceMailServerController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMailServer, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMailServer, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
						    	var strInfo = "";
							var tmp = rec.mail == null ? "" : rec.mail.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMailServer, RoleType.修改))
							{
								<text>
					    			strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
					    			</text>
							}
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMailServer, RoleType.删除))
							{
								<text>
					    			if (strInfo != "") {
					    				strInfo += "&nbsp;|&nbsp;";
					    			}
					    			strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
					    			</text>
							}
					    		return strInfo;
						}
					},
					</text>
				}
				{ field: "mail", title: "@Resources.Mail", align: "center", sortable: true, width: 250 },
				{ field: "mailServer", title: "@Resources.MailServer", align: "center", sortable: true, width: 150 },
				{
					field: "mailType", title: "@Resources.MailType", align: "center", sortable: true, width: 150,
					formatter: function(value, rec) {
	                			if (value=="@ConstValues.MailType.会议邮箱") {
	                				return "@Resources.MailConference";
	                			} else if (value=="@ConstValues.MailType.注册服务邮箱") {
	                				return "@Resources.MailAttendence";
	                			} else if (value=="@ConstValues.MailType.投稿服务邮箱") {
	                				return "@Resources.MailContribute";
	                			} else if (value=="@ConstValues.MailType.酒店交通服务邮箱") {
	                				return "@Resources.MailHotelTraffic";
	                			}
					}
				},
				{
	        			field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
	                			if (value=="@ConstValues.Status.正常") {
	                				return "@Resources.Normal"
	                			} else {
	                				return "@Resources.Pause"
	                			}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			}
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function deleteData(id,mailServer) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, mailServer);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidId").val(id);
				$.post("@Url.Action(nameof(ConferenceMailServerController.Delete),
						nameof(ConferenceMailServerController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtMail").textbox("setValue","");
		$("#txtMailServer").textbox("setValue","");
		$("#txtMailPassword").textbox("setValue","");
		$("#ddlMailType").combobox("setValue","");
		$("#txtCcMail").textbox("setValue","");
		$("#txtRemark").textbox("setValue","");

		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceMailServerController.GetEditData),
				nameof(ConferenceMailServerController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#txtMail").textbox("setValue",data.data.mail);
				$("#txtMailServer").textbox("setValue",data.data.mailServer);
				$("#txtMailPassword").textbox("setValue",data.data.password);
				$("#ddlMailType").combobox("setValue",data.data.mailType);
				$("#txtCcMail").textbox("setValue",data.data.ccMail);
				$("#ddlStatus").combobox("setValue",data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue",data.data.remark);
				$("#hidId").val(id);
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceMailServerController.Create),
									nameof(ConferenceMailServerController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceMailServerController.Modify),
									nameof(ConferenceMailServerController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			})
		}
	};

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelMail: $("#selMail").textbox("getValue")
		});
	}
</script>
}